package com.suifeng.mq.order.web;

import com.suifeng.mq.common.utils.UuidUtils;
import com.suifeng.mq.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
public class TestController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/test/createOrder")
    @ResponseBody
    public String createOrderTest(){

        //订单下单成功
        OrderEntity orderEntity = new OrderEntity();
        String uuid = UuidUtils.generateUuid();
        orderEntity.setOrderSn(uuid);
        orderEntity.setCreateTime(new Date());

        //给MQ发消息
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",orderEntity,new CorrelationData(uuid));
        return "ok";
    }

}
